In [1]:
%reload_ext autotime
import geopandas as gpd
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from sklearn.cluster import KMeans
import plotly.express as px
from sklearn.preprocessing import StandardScaler
from shapely import box
pd.set_option('display.max_columns', 500)
✔️ 1.39 s (2024-12-03T16:15:02/2024-12-03T16:15:03)
In [2]:
df = gpd.read_parquet("areas.parquet").dropna().reset_index(drop=True)
df
✔️ 4.21 s (2024-12-03T16:15:03/2024-12-03T16:15:08)
Out[2]:
geometry area old_min old_max old_mean old_median old_std new_min new_max new_mean new_median new_std diff_min diff_max diff_mean diff_median diff_std distance_to_river Class_2018 Wetland_18 Onshore_18 old_roughness_min old_roughness_max old_roughness_mean old_roughness_median old_roughness_std new_roughness_min new_roughness_max new_roughness_mean new_roughness_median new_roughness_std diff_roughness_min diff_roughness_max diff_roughness_mean diff_roughness_median diff_roughness_std old_slope_min old_slope_max old_slope_mean old_slope_median old_slope_std new_slope_min new_slope_max new_slope_mean new_slope_median new_slope_std diff_slope_min diff_slope_max diff_slope_mean diff_slope_median diff_slope_std old_aspect_min old_aspect_max old_aspect_mean old_aspect_median old_aspect_std new_aspect_min new_aspect_max new_aspect_mean new_aspect_median new_aspect_std diff_aspect_min diff_aspect_max diff_aspect_mean diff_aspect_median diff_aspect_std old_curvature_min old_curvature_max old_curvature_mean old_curvature_median old_curvature_std new_curvature_min new_curvature_max new_curvature_mean new_curvature_median new_curvature_std diff_curvature_min diff_curvature_max diff_curvature_mean diff_curvature_median diff_curvature_std old_terrain_ruggedness_index_min old_terrain_ruggedness_index_max old_terrain_ruggedness_index_mean old_terrain_ruggedness_index_median old_terrain_ruggedness_index_std new_terrain_ruggedness_index_min new_terrain_ruggedness_index_max new_terrain_ruggedness_index_mean new_terrain_ruggedness_index_median new_terrain_ruggedness_index_std diff_terrain_ruggedness_index_min diff_terrain_ruggedness_index_max diff_terrain_ruggedness_index_mean diff_terrain_ruggedness_index_median diff_terrain_ruggedness_index_std old_rugosity_min old_rugosity_max old_rugosity_mean old_rugosity_median old_rugosity_std new_rugosity_min new_rugosity_max new_rugosity_mean new_rugosity_median new_rugosity_std diff_rugosity_min diff_rugosity_max diff_rugosity_mean diff_rugosity_median diff_rugosity_std old_profile_curvature_min old_profile_curvature_max old_profile_curvature_mean old_profile_curvature_median old_profile_curvature_std new_profile_curvature_min new_profile_curvature_max new_profile_curvature_mean new_profile_curvature_median new_profile_curvature_std diff_profile_curvature_min diff_profile_curvature_max diff_profile_curvature_mean diff_profile_curvature_median diff_profile_curvature_std old_planform_curvature_min old_planform_curvature_max old_planform_curvature_mean old_planform_curvature_median old_planform_curvature_std new_planform_curvature_min new_planform_curvature_max new_planform_curvature_mean new_planform_curvature_median new_planform_curvature_std diff_planform_curvature_min diff_planform_curvature_max diff_planform_curvature_mean diff_planform_curvature_median diff_planform_curvature_std
0 POLYGON ((2004202 5686800, 2004202 5686799, 20... 46435.0 239.875000 581.692017 432.621765 445.957001 74.112358 239.446991 582.225952 433.723755 446.968994 74.084862 -12.535980 17.803986 1.101900 0.923981 1.049551 53.256848 40.0 False True 0.659973 35.306030 5.486135 4.675980 2.959646 0.598022 36.598022 5.504868 4.660004 3.080257 0.091980 24.277985 1.431480 0.976013 1.514268 12.191864 85.645755 60.792847 60.529063 9.767506 14.545549 86.264849 60.798460 60.323333 9.655671 0.084189 82.579881 18.996306 14.869672 14.828664 0.053437 359.903937 64.345379 61.655388 27.287424 0.075001 359.569282 64.703603 61.589641 28.575269 0.000000 359.998904 174.475804 177.977200 102.097923 -4106.994629 3473.999023 -1.254920 1.397705 146.702757 -3068.005371 2375.000000 0.462927 0.909424 173.014103 -3780.404663 5885.586548 1.717851 -4.809570 195.810023 0.707826 42.501035 5.289730 4.426396 2.950893 0.691538 38.838588 5.335738 4.387030 3.196659 0.094361 48.114773 1.673626 1.132609 1.854021 1.043548 15.471595 2.396650 2.055446 1.097096 1.042409 16.187036 2.406698 2.041582 1.173803 1.001085 15.716347 1.306963 1.126269 0.599152 -2173.076493 1768.643498 1.366716 -0.772895 101.788433 -1615.339143 2009.492962 -0.091207 -1.074648 127.388097 -2748.394431 2442.874912 3.655153 4.824488 120.129857 -2391.628253 2107.783009 0.111796 0.983236 64.695883 -1168.404426 1070.992710 0.371720 0.176987 65.956356 -1850.208135 3137.192117 5.373005 1.279411 97.218072
1 POLYGON ((2004467 5685771, 2004467 5685770, 20... 29403.0 497.904022 654.613953 582.098328 584.377014 34.089294 498.463989 655.286011 582.956116 585.226990 34.127289 -2.153992 10.362000 0.857765 0.794983 0.576162 363.633366 40.0 False True 1.014038 18.124939 3.542689 3.311951 1.276278 1.090027 19.531006 3.562541 3.312012 1.333139 0.107971 9.908020 0.931755 0.800964 0.655193 20.669869 81.677298 52.486562 52.491020 7.571216 21.450877 82.821445 52.555452 52.308983 7.401109 0.090959 76.596840 13.897688 11.971204 9.680113 0.571980 359.904721 72.098850 70.385071 23.447301 0.084092 359.832807 72.077946 70.051588 23.447828 0.000000 359.998183 174.895254 174.687390 102.772624 -565.490723 728.393555 -0.436127 0.305176 71.876470 -799.804688 1380.200195 0.314705 -0.988770 88.971362 -786.187744 1353.405762 0.750868 -3.387451 105.736501 0.967801 16.670053 3.456795 3.255530 1.209232 1.057733 19.682388 3.485316 3.233786 1.323116 0.098895 12.520586 1.098408 0.922901 0.811272 1.076200 6.912644 1.741509 1.660006 0.424882 1.085873 8.210388 1.749132 1.653080 0.462895 1.001649 4.462226 1.138265 1.088307 0.216750 -446.608314 424.710959 0.355590 0.064584 46.059039 -834.909221 621.552639 -0.139612 0.588905 59.766936 -804.891902 563.984020 2.491287 3.496640 62.815394 -248.181600 360.790659 -0.080538 0.395551 35.695038 -492.481522 701.500712 0.175093 0.126739 40.445882 -404.546788 720.480309 3.242155 1.301183 54.727808
2 POLYGON ((2004873 5686570, 2004873 5686569, 20... 12183.0 227.065994 256.863007 235.661514 235.633011 5.262484 226.535995 257.285004 234.251129 233.921005 5.208738 -5.269012 1.388000 -1.410383 -1.268005 0.959620 0.000000 12.0 False True 0.013992 12.281998 0.680187 0.339996 0.980767 0.000000 11.062012 0.705074 0.304001 1.090299 0.015991 4.386017 0.570605 0.384018 0.564009 0.020247 79.793556 12.457453 7.188113 13.430974 0.000000 79.707626 12.367646 6.160058 15.241137 0.083814 63.463752 10.655974 7.349124 10.160879 0.000000 359.997918 143.672330 61.096807 134.723424 0.000000 359.999830 178.271537 202.531218 127.941584 0.000000 359.994093 181.516457 196.555429 93.886035 -785.794067 565.798950 -0.258252 -0.701904 37.304708 -609.600830 640.200806 -5.819703 -0.399780 40.725587 -676.596069 639.401245 -5.561482 -2.401733 46.637429 0.018537 13.625843 0.686415 0.342783 1.076525 0.000000 14.146038 0.717151 0.327071 1.169361 0.013704 6.289610 0.613839 0.413557 0.633036 1.000031 5.673030 1.083662 1.010065 0.294529 1.000000 5.625438 1.097992 1.009577 0.304941 1.000035 2.489752 1.056729 1.015757 0.124731 -465.677685 550.854529 0.543762 0.644415 29.884640 -483.367530 591.292829 5.457412 0.372078 33.412884 -367.705565 431.473932 3.977466 1.496627 30.887935 -234.939538 218.020061 0.285510 0.061352 13.630589 -197.421854 248.658820 -0.362331 -0.027325 14.184576 -391.844280 271.695680 -1.584016 -0.475870 22.683974
3 POLYGON ((2004160 5686276, 2004160 5686259, 20... 7936.0 426.713989 481.050018 454.960205 454.101990 11.115774 425.688995 480.164001 451.769012 450.686523 12.227842 -11.742004 0.250000 -3.191185 -2.933502 2.077569 105.981601 40.0 False True 0.115997 2.864014 1.088911 1.035004 0.444085 0.160004 3.548004 1.149903 1.089996 0.379556 0.101990 3.790985 0.928983 0.833984 0.485503 0.631207 52.194008 22.075146 21.772187 8.436651 0.444084 51.141886 23.237991 22.736597 7.209435 0.127753 54.832468 17.370628 16.072876 9.549888 0.000409 359.998718 268.658801 292.598580 87.956669 0.083791 359.916207 283.686293 292.940889 58.707740 0.001329 359.944450 191.959304 215.612298 107.909282 -385.400391 266.003418 0.965183 1.202393 35.828859 -209.497070 462.396240 -0.834379 -2.587891 38.762123 -266.104126 474.600220 -1.799513 -3.402710 52.583506 0.104640 3.180785 1.088018 1.032388 0.445381 0.178691 3.332881 1.149534 1.090320 0.375238 0.107257 3.866254 0.974496 0.890775 0.479665 1.002701 1.643132 1.107598 1.086444 0.082272 1.003647 1.665576 1.114834 1.096533 0.071184 1.002029 1.776804 1.094753 1.069019 0.086614 -126.595715 190.067771 -0.499714 -0.470120 22.018023 -220.954790 135.179083 0.729974 1.285756 22.816156 -226.703591 195.120966 1.292222 2.144601 31.276009 -195.332620 139.407703 0.465469 0.678547 18.579442 -167.001436 241.441450 -0.104405 -0.665657 20.813181 -134.150583 247.896628 -0.507291 -1.203775 28.171378
4 POLYGON ((2003987 5685256, 2003987 5685248, 20... 4564.0 423.951019 497.674011 455.302734 452.955505 15.822889 423.898987 496.877014 453.009827 450.873993 15.633767 -11.445007 1.221008 -2.292885 -1.741989 1.880821 0.000000 52.0 False True 0.157990 11.141022 3.232546 2.923019 1.665596 0.188019 12.792999 3.920331 3.688004 1.792707 0.234039 10.397003 2.364265 1.947998 1.555697 1.364010 76.591306 46.512413 48.821698 14.828230 1.403381 80.486373 51.374083 53.853323 15.125011 0.752549 78.238272 34.087520 32.213045 18.073260 0.138505 359.652084 188.928666 222.486419 98.876330 0.267126 359.843455 168.479527 211.234308 99.788719 0.021159 359.736418 172.755016 179.704520 101.393019 -645.391846 600.994873 -5.377059 0.250244 103.789316 -846.899414 620.404053 -33.064600 -14.804077 128.301360 -1160.992432 818.386841 -27.687622 -17.544556 156.646921 0.132466 10.110447 3.182110 2.948608 1.577308 0.176762 14.364372 3.921027 3.581953 1.890567 0.210936 11.567636 2.569666 2.094435 1.704384 1.002362 4.343685 1.676904 1.560548 0.513034 1.004936 6.107690 1.905294 1.754129 0.641131 1.007361 4.972207 1.513855 1.334589 0.510903 -358.040086 453.698537 3.130396 -0.037930 64.227149 -389.285650 817.634632 26.466625 7.956602 97.813627 -386.344111 740.299464 12.122084 6.297832 101.786500 -378.663835 365.666206 -2.246663 0.396343 54.278794 -430.431501 312.396791 -6.597975 -2.694242 51.253638 -554.358201 467.979155 -15.565538 -9.080177 78.540318
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
21845 POLYGON ((2059678 5756841, 2059678 5756839, 20... 4735.0 71.222000 179.138000 122.841553 125.296005 26.810328 70.716003 178.631989 121.686890 123.921997 26.839592 -6.761993 0.975006 -1.154655 -0.977997 0.776434 0.000000 52.0 False True 0.220001 10.423004 4.026168 3.990005 1.554880 0.073997 8.178001 3.944565 3.967995 1.417332 0.103996 5.936020 1.278031 1.105003 0.756630 1.017780 76.635221 54.334486 57.142925 11.787876 1.037195 73.236060 54.143909 57.245595 12.076691 0.281992 69.995038 20.996818 19.020741 12.400439 20.806287 291.447758 195.716227 201.657146 31.896528 2.602788 357.481168 196.418623 202.439664 29.906916 0.164631 359.888539 173.588015 174.344804 103.890883 -567.898560 819.601440 2.176501 1.400757 91.576662 -487.200928 297.698975 -8.875055 -3.601074 59.477399 -825.604248 549.099731 -11.051568 -9.202576 104.083685 0.273647 10.744067 3.929377 3.892496 1.568549 0.081759 8.182450 3.813081 3.865290 1.378545 0.139181 8.886453 1.420335 1.244166 0.850241 1.010414 4.681822 1.914410 1.869739 0.529715 1.000928 3.494128 1.875642 1.862606 0.452838 1.002673 3.169958 1.197974 1.137516 0.209613 -415.345421 328.101320 -1.014716 -1.079542 56.836539 -190.684123 335.663862 5.846638 2.449064 37.750245 -420.756097 431.424648 0.551748 0.806315 59.623286 -284.354549 436.914244 1.161785 0.977316 47.496931 -232.722963 172.470442 -3.028417 -0.859566 31.362350 -477.117956 349.904132 -10.499820 -7.743738 57.528584
21846 POLYGON ((2059443 5758797, 2059443 5758795, 20... 4467.0 32.271000 35.838001 35.196594 35.352001 0.617860 32.857998 36.693001 36.112537 36.292000 0.588942 -0.430996 2.542000 0.915942 0.905003 0.267722 0.000000 40.0 False True 0.014000 2.315998 0.112919 0.070000 0.193626 0.006001 2.170002 0.136516 0.090000 0.183198 0.009998 1.987999 0.168005 0.104000 0.216333 0.028550 46.104620 2.074332 1.186823 4.036364 0.000055 40.132804 2.733354 1.758152 3.808287 0.028659 42.089060 3.146539 1.816141 4.496276 0.000000 359.999007 178.159519 146.741870 123.277144 0.000000 359.999485 181.076416 156.565986 132.158858 0.000000 359.997723 182.405069 179.998699 113.629610 -210.599518 236.599731 -0.220678 0.099945 14.554311 -174.899292 213.000488 0.995671 0.899506 12.143754 -242.800522 211.199951 1.216352 0.799942 18.991054 0.014664 3.233438 0.125398 0.077674 0.237803 0.007937 2.421731 0.146144 0.094509 0.202771 0.011491 3.179989 0.187792 0.115199 0.265684 1.000043 1.518275 1.005311 1.000647 0.035934 1.000010 1.334424 1.005112 1.000873 0.023233 1.000030 1.483220 1.008331 1.001385 0.035747 -177.153020 159.143346 0.090669 0.009550 11.438680 -131.945382 131.027588 -0.955774 -0.591607 8.173938 -156.383182 175.658685 -0.933835 -0.644400 13.752256 -81.913252 59.446711 -0.130009 0.080154 5.149047 -79.763715 94.858104 0.039597 0.180451 5.913490 -77.056582 101.627277 0.281014 0.116568 8.075569
21847 POLYGON ((2059696 5758532, 2059696 5758531, 20... 4440.0 24.914999 33.780998 31.295317 32.326000 2.329670 25.475000 36.038998 32.241283 33.126503 2.212822 -0.499001 3.468998 0.945970 0.785999 0.505774 0.000000 21.0 False True 0.020000 2.696999 0.479091 0.223999 0.529890 0.020000 2.532999 0.611072 0.426003 0.497583 0.016003 2.404999 0.504862 0.400002 0.386986 0.020246 48.227992 9.943480 4.391600 11.185112 0.028632 46.602692 12.602290 8.480658 10.512693 0.020285 42.424041 9.679583 7.232482 7.990317 0.355672 359.664492 179.575440 192.315706 76.769308 0.000000 359.998369 175.067945 190.653882 84.478878 0.000000 359.999820 163.835761 170.800042 110.385358 -158.399963 152.899933 -1.185186 -0.600433 21.778402 -167.399597 214.999390 4.017137 1.700592 25.676492 -203.300095 226.600266 5.202334 2.998734 33.867397 0.021445 2.784960 0.506292 0.237632 0.548552 0.017320 2.776767 0.632906 0.446037 0.512790 0.021072 2.997100 0.538978 0.432070 0.410317 1.000071 1.507046 1.043235 1.005339 0.075308 1.000033 1.461789 1.052387 1.017225 0.069529 1.000068 1.488485 1.037979 1.017717 0.053006 -96.843867 88.141545 1.099843 0.576600 14.629816 -164.701545 89.570958 -1.942252 -0.744439 16.236581 -170.705364 119.650385 -2.260467 -1.212805 20.310909 -74.771232 57.694364 -0.085343 0.150589 10.492132 -88.590114 103.961346 2.074886 0.873680 13.336787 -113.013243 108.612276 2.941867 1.477503 18.272839
21848 POLYGON ((2058850 5756947, 2058850 5756941, 20... 4287.0 354.406006 423.560974 393.562653 399.283997 20.062107 353.753998 422.947021 391.819214 397.509979 20.178522 -5.649017 0.132019 -1.743446 -1.509003 1.041421 179.116354 52.0 False True 0.190002 5.382019 1.750105 1.658005 0.751046 0.490021 3.150970 1.756703 1.737000 0.375511 0.075989 3.704041 0.984824 0.906006 0.534759 0.648426 66.945243 33.729416 34.104210 10.314899 11.287575 50.792861 34.907940 34.774446 5.410479 0.286363 58.062818 19.166147 18.407946 10.136939 6.289008 280.681795 181.240798 182.217013 32.123952 116.872198 273.086219 180.901765 177.380321 28.616572 0.000000 359.670416 176.443576 167.890273 100.564330 -312.695312 375.207520 6.855208 0.201416 42.280645 -121.405029 109.295654 -3.669346 -2.099609 20.484973 -382.815552 329.495239 -10.524530 -6.401062 46.320336 0.213991 6.416266 1.779555 1.699625 0.720760 0.486213 3.007439 1.747157 1.711379 0.345474 0.084126 5.054162 1.014063 0.939521 0.548451 1.003810 2.596080 1.256068 1.217094 0.184965 1.020529 1.599213 1.233890 1.220114 0.082958 1.000812 2.012523 1.102480 1.073752 0.102582 -271.899219 236.116467 -4.415631 -0.176631 26.403004 -68.383950 74.408718 1.134758 0.500894 11.352410 -251.957347 268.014700 5.601500 2.666749 28.189708 -155.802293 165.066978 2.439577 0.103849 22.896709 -72.631808 73.052577 -2.534588 -0.993262 12.433742 -153.613620 162.610466 -4.923029 -2.738370 25.562239
21849 POLYGON ((2060908 5757824, 2060908 5757823, 20... 4177.0 106.665001 156.914001 134.658188 135.246994 12.084222 106.139999 155.028000 130.776230 131.284988 10.852175 -16.059998 0.482986 -3.881956 -2.633011 3.386646 229.533617 71.0 False True 0.192001 6.001007 1.925268 1.688004 0.956849 0.035995 8.449005 1.579540 1.250000 1.377060 0.186005 6.151993 1.872114 1.634003 1.022598 0.882394 67.587112 34.416495 32.248930 13.348918 0.270078 75.230540 26.604492 24.741962 19.122158 0.762521 68.021847 32.318763 31.215687 14.261081 0.119032 359.959068 243.733649 237.591606 65.916311 0.079423 359.109464 198.980670 209.171861 62.871769 0.030036 359.910143 168.295570 167.609361 97.088656 -266.998291 299.395752 6.862473 5.200195 41.666913 -378.302002 416.302490 -7.808048 -1.202393 53.341343 -414.503479 440.299988 -14.670534 -11.698151 66.967031 0.257590 5.811946 1.899690 1.598325 0.982498 0.036168 9.342299 1.583155 1.311894 1.372454 0.213907 6.316297 1.892568 1.655871 0.996818 1.006074 2.644130 1.300639 1.193077 0.263588 1.000200 3.954532 1.263774 1.133288 0.351497 1.006936 2.710796 1.299711 1.206651 0.269398 -203.222592 144.231965 -4.100455 -2.692590 24.879455 -260.524544 287.215213 6.064958 0.633018 40.296262 -197.223107 271.283075 8.796612 6.158019 42.898662 -122.766326 162.590976 2.762017 2.317776 22.884212 -162.141919 155.777946 -1.743089 -0.262324 21.122610 -244.622442 252.672584 -5.873922 -4.587378 34.467993

21850 rows × 141 columns

In [3]:
features = df.drop(columns="geometry")
scaled_features = StandardScaler().fit_transform(features)
clusters = KMeans(n_clusters=25).fit_predict(scaled_features)
unique_values, counts = np.unique(clusters, return_counts=True)
plt.bar(unique_values.astype(str), counts)
✔️ 1.18 s (2024-12-03T16:15:08/2024-12-03T16:15:09)
Out[3]:
<BarContainer object of 25 artists>
No description has been provided for this image
In [4]:
df["cluster"] = clusters
✔️ 2.09 ms (2024-12-03T16:15:09/2024-12-03T16:15:09)
In [5]:
bbox = box(2053600, 5802000, 2058400, 5809200)
subset = df[df.within(bbox)]
display(subset.cluster.value_counts())
print(subset.shape)
subset.explore("cluster", legend=True, tooltip="cluster", categorical=True, tiles="ESRI.WorldImagery")
✔️ 4.85 s (2024-12-03T16:15:09/2024-12-03T16:15:14)
cluster
11    28
23    18
1     16
24    14
5     12
3     12
12    12
6     10
0      9
8      9
21     9
13     8
2      8
10     5
16     4
9      4
18     4
19     3
22     1
4      1
14     1
Name: count, dtype: int64
(188, 142)
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook